package com.hktf.corelib.utils;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

/**
 * @author 陈大专
 * @time 2023/11/10 11:49
 * @des 诊断资源工具类
 **/
public class DiagnoseResUtil {

    /**
     * @param path
     * @return
     */
    public static String getSdVersion(String path) {
        String version = "000000000";
        String tempString;
        File versionFile = new File(path);
        BufferedReader reader = null;
        if (versionFile.exists()) {
            try {
                reader = new BufferedReader(new FileReader(versionFile));
                tempString = reader.readLine();
                //                LogMds.d(TAG, "version:" + tempString);
                if (tempString != null) { //&& tempString.length() == 9
                    version = tempString;
                }
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                if (reader != null) {
                    try {
                        reader.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
        return version;
    }

    /**
     * @param systemNum
     * @return
     */
    public static String getSdVersionBySystemNum(String systemNum) {
        String path = Config.getDiaSysRes() + systemNum + "/Version.txt";
        return getSdVersion(path);
    }

    /*
     *
     *0：两边版本一致  1：车主版本比技师低  2：车主版本比技师高
     * */
    public static int compare(String currentVersion, String newVersion) {
        if (currentVersion.equals(newVersion)) {
            return 0;
        } else if (newVersion.compareToIgnoreCase(currentVersion) > 0) {
            return 1;
        }
        return 2;
    }

}
